package org.kfive.nova.functional;

import java.util.function.Supplier;

/**
 * Created by zhanwu.lzw on 2017/11/14.
 */
public class LazyHolder<T> implements Supplier<T> {

    private Supplier<T> cache;

    public LazyHolder(Supplier<T> supplier) {
        this.cache = ()->{
            T value = supplier.get();
            cache = ()-> value;
            return value;
        };
    }

    /**
     * Gets a result.
     *
     * @return a result
     */
    @Override
    public T get() {
        return cache.get();
    }
}
